/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define OMEN_SOURCE 1

#include "OmenMaterial.h"
#include <IOmenFactory.h>

using namespace Omen;

Material::Material()
{
    m_ambient = m_diffuse = m_specular = Omen::Vector4d( 0.5, 0.5, 0.5, 1.0 );
    m_shininess = 50.0;
}

Material::Material( const Omen::Material& other )
{
    std::vector< std::unique_ptr<Omen::ITexture> >  m_textures;
    /*for( auto p = other.m_textures.begin(); p != m_textures.end(); ++p )
    {
        std::vector<std::unique_ptr<Omen::ITexture> >::const_iterator pTexture = p;
        std::unique_ptr<Omen::ITexture> newTexture = GetOmenFactory().newTextureObject();
        
        m_textures.push_back( newTexture );
    }*/
}

Material::~Material()
{
}

std::wstring Material::name() const
{
    return m_name;
}

std::wstring& Material::name()
{
    return m_name;
}

Omen::Vector4d  Material::ambientColor() const
{
    return m_ambient;
}
Omen::Vector4d& Material::ambientColor()
{
    return m_ambient;
}

Omen::Vector4d  Material::diffuseColor() const
{
    return m_diffuse;
}

Omen::Vector4d& Material::diffuseColor()
{
    return m_diffuse;
}

Omen::Vector4d  Material::specularColor() const
{
    return m_specular;
}

Omen::Vector4d& Material::specularColor()
{
    return m_specular;
}

Omen::Float     Material::shininess() const
{
    return m_shininess;
}

Omen::Float&    Material::shininess()
{
    return m_shininess;
}

std::wstring    Material::textureFilename() const
{
    if( !m_texture )
    {
        return L"";
    }
    else
        return m_texture->filePath();
}

std::wstring&   Material::textureFilename()
{
    static std::wstring strTextureEmptyFilePath;
    return this->m_textureFilename;
    if( !m_texture )
    {
        return strTextureEmptyFilePath;
    }
    else
        return m_texture->filePath();
}

bool Material::operator ==( const std::wstring name ) const
{
    return m_name == name;
}

unsigned int Material::numTextures() const
{
    return 1; //m_textures.size();
}

std::unique_ptr<Omen::ITexture>& Material::texture( unsigned int iTexture )
{
    if( m_texture )
        return m_texture;
    else
        throw std::runtime_error( "Omen::Material, invalid texture index!" );
}

void Material::setTexture( unsigned int iTexture, std::unique_ptr<Omen::ITexture> texture )
{
    //m_textures.at(iTexture) = std::move(texture);
    m_texture.reset( std::move(texture).get() );
    
}

void Material::addTexture( std::unique_ptr<Omen::ITexture> texture )
{
    m_texture.reset( std::move(texture).get() );
}
    
    
/// EOF